import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/about',
  //   name: 'About',
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
  {
    path: '/dashborad',
    name: 'dashborad',
    redirect:'/dashborad/home',
    component: () => import(/* webpackChunkName: "about" */ '../views/Dashborad.vue'),
    children:[
      {
        path: '/dashborad/home',
        name: 'home',
        meta:{index:1},
        component: () => import(/* webpackChunkName: "about" */ '../views/home/Home.vue'),
      },
      {
        path: '/dashborad/lesson',
        name: 'lesson',
        meta:{index:1},
        component: () => import(/* webpackChunkName: "about" */ '../views/lesson/Lesson.vue'),
      },
      {
        path: '/dashborad/cycle',
        name: 'cycle',
        meta:{index:1},
        component: () => import(/* webpackChunkName: "about" */ '../views/cycle/Cycle.vue'),
      },
      {
        path: '/dashborad/my',
        name: 'my',
        meta:{index:1},
        component: () => import(/* webpackChunkName: "about" */ '../views/my/My.vue'),
      }
    ]
  },
  {
    path: '/check',
    meta:{index:2},
    component: () => import(/* webpackChunkName: "about" */ '../views/check/Checkout.vue'),
  },
  {
    path: '/list',
    meta:{index:2},
    component: () => import(/* webpackChunkName: "about" */ '../views/distribution/List.vue'),
  },
  {
    path: '/lessonapprove',
    meta:{index:3},
    component: () => import(/* webpackChunkName: "about" */ '../views/approver/Lessonapprove.vue'),
  },
  {
    path: '/lessondel',
    meta:{index:3},
    component: () => import(/* webpackChunkName: "about" */ '../views/approver/Dellesson.vue'),
  },
  {
    path: '/addpeople',
    meta:{index:3},
    component: () => import(/* webpackChunkName: "about" */ '../views/approver/Addpeople.vue'),
  },
  {
    path: '/delpeople',
    meta:{index:3},
    component: () => import(/* webpackChunkName: "about" */ '../views/approver/Delpeople.vue'),
  },
  {
    path: '/dispose',
    meta:{index:3},
    component: () => import(/* webpackChunkName: "about" */ '../views/approver/myapprove/Dispose.vue'),
  },
  {
    path: '/disposedetail',
    meta:{index:4},
    component: () => import(/* webpackChunkName: "about" */ '../views/approver/myapprove/DisposeDetail.vue'),
  },
  {
    path: '/approvehome',
    meta:{index:2},
    component: () => import(/* webpackChunkName: "about" */ '../views/approver/Approvehome.vue'),
  },
  {
    path: '/dispeople',
    meta:{index:3},
    component: () => import(/* webpackChunkName: "about" */ '../views/distribution/Dispeople.vue'),
  },
  {
    path: '/role',
    meta:{index:4},
    component: () => import(/* webpackChunkName: "about" */ '../views/distribution/Role.vue'),
  },
  {
    path: '/changepart',
    meta:{index:4},
    component: () => import(/* webpackChunkName: "about" */ '../views/distribution/Changepart.vue'),
  },
  {
    path: '/lessonlist',
    meta:{index:2},
    component: () => import(/* webpackChunkName: "about" */ '../views/lesson/list/Lessonlist.vue'),
  },
  {
    path: '/details',
    meta:{index:3},
    component: () => import(/* webpackChunkName: "about" */ '../views/lesson/list/Details.vue'),
  },
  {
    path: '/pdf',
    meta:{index:4},
    component: () => import(/* webpackChunkName: "about" */ '../views/lesson/list/Pdf.vue'),
  },
  {
    path: '/video',
    meta:{index:4},
    component: () => import(/* webpackChunkName: "about" */ '../views/lesson/list/Video.vue'),
  },
  {
    path: '/extravideo',
    meta:{index:4},
    component: () => import(/* webpackChunkName: "about" */ '../views/lesson/list/Extravideo.vue'),
  },
  {
    path: '/approver',
    meta:{index:5},
    component: () => import(/* webpackChunkName: "about" */ '../views/lesson/list/Approver.vue'),
  },
  {
    path: '/login',
    meta:{index:0},
    component: () => import(/* webpackChunkName: "about" */ '../views/login/Login.vue'),
  },
  {
    path: '/',
    redirect:'/dashborad'
  },
  {
    path: '*',
    redirect:'/dashborad'
  },
]

const router = new VueRouter({
  routes
})
// 登录状态验证
router.beforeEach((to,from,next)=>{
  if(to.path == '/login') return next();
  const token = localStorage.getItem('token');
  if(token) return next();
  router.push('/login'); 
})
// 解决重复点击报错
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

export default router
